/*
 * FPagoAdmin.java
 *
 * Created on September 3, 2007, 10:16 AM
 */

package administrador;

/**
 *
 * @author  Maria Palacios
 */
public class FPagoAdmin extends javax.swing.JFrame {
boolean registraFP=false;
Facturacion f;
NotaCD nCD;
Nota_de_Venta notaVenta;
Conexion conexion;
int numFact;
String bandera;
Usuario user;


    /** Creates new form FPagoAdmin */
    public FPagoAdmin(Facturacion fEnt,Conexion cEnt,int numFactE,Usuario user) {
        this.user=user;
        bandera="Facturacion";
        conexion=cEnt;
        initComponents();
        f=fEnt;
        setVisible(true);
        setSize(440,180);
        numFact=numFactE;
   
    }
    
    public FPagoAdmin(NotaCD fEnt,Conexion cEnt,int numFactE,Usuario user) {
        this.user=user;
        bandera="NotasCD";
        conexion=cEnt;
        initComponents();
        nCD=fEnt;
        setVisible(true);
        setSize(440,180);
        numFact=numFactE;
        
    }
    public FPagoAdmin(Nota_de_Venta nEnt,Conexion cEnt,int numFactE,Usuario user) {
        this.user=user;
        bandera="NotadeVenta";
        conexion=cEnt;
        initComponents();
        notaVenta=nEnt;
        setVisible(true);
        setSize(440,180);
        numFact=numFactE;
       
    }
    
   
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cb_opcion = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Definir Forma de Pago"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Forma de Pago:");

        cb_opcion.setFont(new java.awt.Font("Tahoma", 1, 18));
        cb_opcion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Efectivo", "Tarjeta de Credito", "Cuenta por Cobrar", "Credito" }));
        cb_opcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_opcionActionPerformed(evt);
            }
        });

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cb_opcion, 0, 224, Short.MAX_VALUE))
                .addGap(36, 36, 36))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cb_opcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(57, 57, 57))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
        if (bandera.equals("Facturacion")) {

            //Tomo el tipo de documento a Imprimir:
            String documento;
            documento = "Factura";
            
            if (cb_opcion.getSelectedIndex() == 0) {
               //System.out.println("Elijo pagar con efectivo");
               
                f.registrarFactura(documento, 1,0);
                this.dispose();

            }
            if (cb_opcion.getSelectedIndex() == 1) {
               //System.out.println("Elijo pagar con tarjeta");
               
                Vent_Fpago vfp = new Vent_Fpago(this, f, conexion, numFact, documento, "tarjeta",user);

            }
            if (cb_opcion.getSelectedIndex() == 2) {
               //System.out.println("Se prefiere dar tiempo para el Pago");
              
                Vent_Fpago vfp = new Vent_Fpago(this, f, conexion, numFact, documento, "cuenta",user);

            }
            if (cb_opcion.getSelectedIndex() == 3) {
               //System.out.println("Elijo pagar con Credito");
            
                f.registrarFactura(documento, 1,2);
                this.dispose();
            }

        }
        if (bandera.equals("NotaCD")) {
            //Tomo el tipo de documento a Imprimir:
            String documento;
            documento = "Nota de CD";
            
            
            if (cb_opcion.getSelectedIndex() == 1) {
               //System.out.println("Elijo pagar con tarjeta");
                Vent_Fpago vfp = new Vent_Fpago(this, nCD, conexion, numFact, documento, "tarjeta",user);

            }
            if (cb_opcion.getSelectedIndex() == 2) {
               //System.out.println("Se prefiere dar tiempo para el Pago");
                Vent_Fpago vfp = new Vent_Fpago(this, nCD, conexion, numFact, documento, "cuenta",user);

            }


        }
        
        if (bandera.equals("NotadeVenta")) {
            //Tomo el tipo de documento a Imprimir:
            String documento;
            documento = "Nota de Venta";
            
            if (cb_opcion.getSelectedIndex() == 0) {
               //System.out.println("Elijo pagar con efectivo");
                notaVenta.registrarFactura(documento, 1,0);
                this.dispose();

            }
            if (cb_opcion.getSelectedIndex() == 1) {
               //System.out.println("Elijo pagar con tarjeta");
                Vent_Fpago vfp = new Vent_Fpago(this, notaVenta, conexion, numFact, documento, "tarjeta",user);

            }
            if (cb_opcion.getSelectedIndex() == 2) {
               //System.out.println("Se prefiere dar tiempo para el Pago");
                Vent_Fpago vfp = new Vent_Fpago(this, notaVenta, conexion, numFact, documento, "cuenta",user);

            }
            if (cb_opcion.getSelectedIndex() == 3) {
               //System.out.println("Se pago con credito");
                notaVenta.registrarFactura(documento, 1,2);
                this.dispose();
            }

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cb_opcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_opcionActionPerformed
// TODO add your handling code here:
       
    }//GEN-LAST:event_cb_opcionActionPerformed
    
   
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cb_opcion;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    
}
